package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.AssignHomework;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AssignHomeworkMapper extends BaseMapper<AssignHomework> {

    // 无需 ahID 来创建新记录
    @Insert("INSERT INTO assign_homework (ct_id, ah_category, start_time, end_time, ah_title, requirement, attachment) " +
            "VALUES (#{ctID}, #{ahCategory}, #{startTime}, #{endTime}, #{ahTitle}, #{requirement}, #{attachment})")
    public int insertWithoutAhID(AssignHomework assignHomework);

    // 按照 ctID 查找
    @Select("SELECT * FROM assign_homework WHERE ct_id = #{ctID}")
    public List<AssignHomework> selectByCtID(int ctID);

    // 删除
    @Delete("DELETE FROM assign_homework WHERE ah_id = #{ahID}")
    public int deleteByAhID(int ahID);

    // 更新
    @Update("UPDATE assign_homework SET ct_id = #{ctID}, ah_category = #{ahCategory}, start_time = #{startTime}, end_time = #{endTime}, " +
            "ah_title = #{ahTitle}, requirement = #{requirement}, attachment = #{attachment} WHERE ah_id = #{ahID}")
    public int updateAssignHomework(AssignHomework assignHomework);
}

